<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/12/12
  Time: 17:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>销售退货</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath }/bootstrap/dist/css/bootstrap.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/pages/yzl/css/test.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/plugins/layui/css/layui.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath }/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/bootstrap-table/dist/bootstrap-table.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath }/css/toastr.min.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.10.2.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/bootstrap/dist/js/bootstrap.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/bootstrap-table/dist/bootstrap-table.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/bootstrap-table/src/locale/bootstrap-table-zh-CN.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/plugins/layui/layui.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/js/toastr.min.js"></script>
    <script type="text/javascript">toastr.options.positionClass = 'toast-top-center';</script>
    <script type="text/javascript">
        $(function () {

            //1.初始化Table
            var oTable = new TableInit();
            oTable.Init();

            //2.初始化Button的点击事件
            var oButtonInit = new ButtonInit();
            oButtonInit.Init();

        });


        var TableInit = function () {
            var oTableInit = new Object();
            //初始化Table
            oTableInit.Init = function () {
                $('#tb_departments').bootstrapTable({
                    url: '${pageContext.request.contextPath }/pages/yzl/data/salesReturns.json',         //请求后台的URL（*）
                    method: 'post',                      //请求方式（*）
                    //contentType : "application/x-www-form-urlencoded",
                    toolbar: '#toolbar',                //工具按钮用哪个容器
                    striped: true,                      //是否显示行间隔色
                    cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                    pagination: true,                   //是否显示分页（*）
                    //queryParamsType: "limit",
                    //contentType: "application/x-www-form-urlencoded",
                    sortable: false,                     //是否启用排序
                    sortOrder: "asc",                   //排序方式
                    queryParams: oTableInit.queryParams,//传递参数（*）
                    sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                    pageNumber: 1,                       //初始化加载第一页，默认第一页
                    pageSize: 10,                       //每页的记录行数（*）
                    pageList: [5,10,15,20],        //可供选择的每页的行数（*）
                    search: true,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                    strictSearch: true,
                    showColumns: true,                  //是否显示所有的列
                    showRefresh: true,                  //是否显示刷新按钮
                    minimumCountColumns: 2,             //最少允许的列数
                    //clickToSelect: true,                //是否启用点击选中行
                    height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                    uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
                    showToggle: true,                    //是否显示详细视图和列表视图的切换按钮
                    cardView: false,                    //是否显示详细视图
                    detailView: false,                   //是否显示父子表
                    columns: [{
                        checkbox: true
                    }, /*{
                        field: 'id',
                        title: 'ID'
                    },*/ {
                        field: 'returnsNumber',
                        title: '退货编号'
                    }, {
                        field: 'returnsDate',
                        title: '退货日期'
                    }, {
                        field: 'customer',
                        title: '客户'
                    },
                    {
                        field: 'returnsStatus',
                        title: '状态',
                        formatter:function(value, row, index){
                            if(value == 0){
                                return '处理中'
                            }else if(value == 1){
                                return '退货成功'
                            }else{
                                return 'WTF'
                            }
                        }
                    }, {
                        field: 'returnsExamineStatus',
                        title: '审批状态',
                        formatter: function (value, row, index) {
                            var back = index;
                            if (value == "0") {
                                return '未提交审核'
                            } else if (value == "1") {
                                return '审核中'
                            } else if (value == "2") {
                                return '审核通过'
                            } else {
                                return 'WTF'
                            }
                        }
                    }, {
                        field: 'produceStatus',
                        title: '详情',
                        formatter:function(value, row, index){
                            var back = index;
                            return '<a href="#" onclick="planXq(' + back + ')" >查看详情</a>'
                        }
                    }]
                });
            };

            //得到查询的参数
            oTableInit.queryParams = function (params) {
                var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    limit: params.limit,   //页面大小
                    offset: params.offset/params.limit+1,  //页码
                    demandDate: $("#demandDate_serch").val(),
                    produceStatus: $("#produceStatus_serch").val(),
                    outLibraryStatus: $("#outLibraryStatus_serch").val(),
                    customerId: $("#customerId_serch").val(),
                    entryPerson: $("#entryPerson_serch").val(),
                };
                return temp;
            };
            return oTableInit;
        };


        var ButtonInit = function () {

            var oInit = new Object();
            var postdata = {};

            oInit.Init = function () {
                //初始化页面上面的按钮事件
            };
            return oInit;
        };
    </script>
</head>
<body>

<div class="panel-body" style="padding-bottom:0px;">
    <div class="panel panel-default">
        <div class="panel-heading">查询条件</div>
        <div class="panel-body">
            <form id="formSearch" class="form-horizontal">
                <div class="form-group" style="margin-top:15px">
                    <label class="control-label col-sm-1" for="txt_search_departmentname">日期:</label>
                    <div class="col-sm-1">
                        <select id="txt_search_departmentname" name="materienumber" class="selectpicker show-tick form-control"  data-live-search="false">
                            <option>最近一天</option>
                            <option>最近一星期</option>
                            <option>最近一个月</option>
                        </select>
                    </div>
                    <label class="control-label col-sm-1" for="txt_search_statu" style="width: 30px;">从</label>
                    <div class="col-sm-2">
                        <input type="text" name="demandDate" id="demandDate_serch" lay-verify="date" placeholder="yyyy-mm-dd"
                               autocomplete="off" class="layui-input form-control"
                               onclick="layui.laydate({elem: this})">
                    </div>
                    <label class="control-label col-sm-1" for="txt_search_statu" style="width: 30px;padding-left: 0px;">至</label>
                    <div class="col-sm-2" style="padding-left: 0px;">
                        <input type="text" name="demandDate" id="demandDate_serch1" lay-verify="date" placeholder="yyyy-mm-dd"
                               autocomplete="off" class="layui-input form-control"
                               onclick="layui.laydate({elem: this})">
                    </div>
                    <label class="control-label col-sm-1" for="txt_search_departmentname">相关单位:</label>
                    <div class="col-sm-1">
                        <select id="txt_search_departmentname1" name="materienumber" class="selectpicker show-tick form-control"  data-live-search="false">
                            <option>所有客户</option>
                            <option>￥%……&*</option>
                            <option>*&……%￥</option>
                        </select>
                    </div>
                    <div class="col-sm-1" style="text-align:left;">
                        <button type="button" style="margin-left:50px" id="btn_query" class="btn btn-primary">查询</button>
                    </div>
                    <div class="col-sm-1" style="text-align:left;">
                        <button type="button" id="btn_query3" class="btn btn-default">清除</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div id="toolbar" class="btn-group">
        <button id="btn_add" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新建
        </button>
        <button id="btn_edit" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改
        </button>
        <button id="btn_delete" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
        </button>
        <button id="btn_approved" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>审批
        </button>
        <button id="btn_approved2" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>批量审批
        </button>
        <button id="btn_Undoapproved" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>撤销审批
        </button>
        <button id="btn_Export" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>导出
        </button>
        <button id="btn_Export1" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>打印条形码
        </button>
        <button id="btn_Export2" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>退货处理
        </button>
    </div>

    <div id="toolbarIn" class="btn-group">
        <button id="btn_addIn" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
        </button>
        <button id="btn_deleteIn" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
        </button>
    </div>

    <!--        表格           -->
    <table id="tb_departments"></table>


    <!--          添加表单       -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width: 1000px">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title" id="myModalLabel">新增订单</h4>
                </div>

                <table id="td_addModelTable"></table>

                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary">确定</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>

    <!--          销售计划选择列表       -->
    <div class="modal fade" id="salePlanModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width: 1000px">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title" id="salePlanModelLabel">出库单</h4>
                </div>

                <table id="td_outLibTable"></table>

                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary">确定</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>

</div>



<script>
    $(document).ready(function () {
        $("#btn_add").click(function () {

            $('#td_addModelTable').bootstrapTable({
                dataType: "json",
                method: 'get',
                contentType: "application/x-www-form-urlencoded",
                cache: false,
                toolbar: '#toolbarIn',
                url:"${pageContext.request.contextPath }/pages/yzl/data/saleOutCarList.json",
                columns:[
                    [
                        {
                            field: 'name',
                            title: "出库单号",
                            valign:"middle",
                            align:"center",
                            colspan: 1
                        },
                        {
                            title: "00000000001",
                            valign:"middle",
                            align:"center",
                            colspan: 1,
                        },
                        {
                            title: "出库日期",
                            valign:"middle",
                            align:"center",
                            colspan: 1,
                        },
                        {
                            title: '<input type="text" name="demandDate" id="demandDate_serch1" lay-verify="date"' +
                            '                               placeholder="yyyy-mm-dd"' +
                            '                               autocomplete="off" class="layui-input form-control"' +
                            '                               onclick="layui.laydate({elem: this})">',
                            valign:"middle",
                            align:"center",
                            colspan: 1,
                        },
                        {
                            title: "制单人",
                            valign:"middle",
                            align:"center",
                            colspan: 2,
                        },
                        {
                            title: "鬼",
                            valign:"middle",
                            align:"center",
                            colspan: 2,
                        }
                    ],
                    [
                        {
                            field: 'name',
                            title: '客户',
                            valign:"middle",
                            align:"center",
                            colspan: 1
                        },
                        {
                            title: '<a href="#" onclick="choseCustomer()" >选择客户</a>',
                            valign:"middle",
                            align:"center",
                            colspan: 1,
                        },
                        {
                            title: "销售计划单号",
                            valign:"middle",
                            align:"center",
                            colspan: 1,
                        },
                        {
                            title: '<a href="#" onclick="chosePlanNum()">选择出库单号</a>',
                            //title: '<a href="#" onclick="chosePlanNum()" style="height: 20px;width: 20px">...</a>',
                            valign:"middle",
                            field: 'aa',
                            align:"center",
                            colspan: 1,
                        },
                        {
                            title: "审批人",
                            valign:"middle",
                            align:"center",
                            colspan: 2,
                        },
                        {
                            title: "鬼",
                            valign:"middle",
                            align:"center",
                            colspan: 2,
                        }
                    ],
                    [
                        {
                            field: 'carType',
                            title: '车种',
                            valign:"middle",
                            align:"center"
                        },
                        {
                            field: 'numberP',
                            title: '品编',
                            valign:"middle",
                            align:"center"
                        },
                        {
                            field: 'nameP',
                            title: '品名',
                            valign:"middle",
                            align:"center"
                        },
                        {
                            field: 'batchNumber',
                            title: '批号',
                            valign:"middle",
                            align:"center"
                        },
                        {
                            field: 'barderNumber',
                            title: '条码',
                            valign:"middle",
                            align:"center"
                        },
                        {
                            field: 'returnsQ',
                            title: '退货数量',
                            valign:"middle",
                            align:"center"
                        },
                        {
                            field: 'returnsRes',
                            title: '退货原因',
                            valign:"middle",
                            align:"center"
                        },
                        {
                            field: 'returnsPeice',
                            title: '退货金额',
                            valign:"middle",
                            align:"center"
                        }
                    ]
                ]
            });

            var allRows = $("#tb_departments").bootstrapTable("getData");
            $('#myModal').modal({
                keyboard: true,
            })

        });
        $("#btn_edit").click(function () {

            if ($('#checkbox-id').is(':checked')) {
                console.log(222222222222);
            }

            $('#myModalUpdate').modal({
                keyboard: true,
            })
        });
        $("#btn_delete").click(function () {

            if ($('#checkbox-id').is(':checked')) {
                console.log(333333333333);
            }

            $('#myModalDelete').modal({
                keyboard: true,
            })
        });



        //提交审核
        $("#btn_approved").click(function (){
            //必须选中一条数据
            var checkedItems = $('#tb_departments').bootstrapTable('getSelections');
            var checkedItem = checkedItems[0];
            if(checkedItems <= 0){
                //$("#btn_edit").attr("data-toggle", "");
                //$("#btn_edit").attr("data-target", "");
                toastr.warning('请选择一行信息');
            }else{
                console.log("checkedItems----",checkedItems);
                var arr = filterData(checkedItems);
                console.log("arr",arr);
                if(arr){
                    //执行后台
                    $.ajax({
                        url:"${pageContext.request.contextPath}/yzl/orderApproveds.do",
                        type:"post",
                        data:{"arr":JSON.stringify(arr)},
                        success:function (data) {
                            if(data != 0){
                                toastr.info('操作成功');
                                refreshAjax();
                            }else{
                                toastr.warning('操作失败');
                            }
                        }
                    })
                }else{
                    toastr.warning('不能选择审核中的审核通过的');
                }
            }
        })
    });

    //选择销计划单号
    function chosePlanNum(){
        $('#td_outLibTable').bootstrapTable({
            dataType: "json",
            method: 'get',
            contentType: "application/x-www-form-urlencoded",
            cache: false,
            url:"${pageContext.request.contextPath }/pages/yzl/data/outLiblist.json",
            columns: [{
                checkbox: true
            }, /*{
                        field: 'id',
                        title: 'ID'
                    },*/ {
                field: 'returnNumber',
                title: '出库单号'
            }, {
                field: 'customer',
                title: '客户'
            }, {
                field: 'returnDate',
                title: '出库日期'
            }]
        });
        $('#salePlanModel').modal({
            keyboard: true,
        })
        $($($($($($("#td_addModelTable")[0]).find("thead")[0]).find("tr")[1]).find("th")[3]).find("div")[1]).empty();
        $($($($($($("#td_addModelTable")[0]).find("thead")[0]).find("tr")[1]).find("th")[3]).find("div")[1]).html("#$%^&*(");
        console.log("???????????");
    }
    //选择客户
    function chosecustomer(){
        console.log(2222222222222);
    }
    //计划详情
    function planXq(){
        $('#myModal').modal({
            keyboard: true,
        })

    }

    //选中数据条件筛选
    function filterData(checkedItems){
        var arr = new Array();
        for(var i=0;i<checkedItems.length;i++){
            var orderExamineStatus = checkedItems[i].orderExamineStatus;
            if(orderExamineStatus == "2" || orderExamineStatus == "1"){
                return false
            }else{
                arr.push(checkedItems[i].id);
            }
        }
        return arr;
    }


    //点击查询 重新请求  刷新表格
    function refreshAjax(){
        $("#tb_departments").bootstrapTable('refresh',{url : '${pageContext.request.contextPath }/yzl/customerOrderList.do'});
    }
</script>


<script>
    layui.use(['form', 'layedit', 'laydate'], function() {
        var form = layui.form(),
            layer = layui.layer,
            layedit = layui.layedit,
            laydate = layui.laydate;

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');
        //自定义验证规则
        form.verify({
            title: function(value) {
                if(value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            },
            pass: [/(.+){6,12}$/, '密码必须6到12位'],
            content: function(value) {
                layedit.sync(editIndex);
            }
        });

        //监听提交
        form.on('submit(demo1)', function(data) {
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })
            return false;
        });
    });



</script>

</body>
</html>

